package com.hkts.beltweigher.master.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hkts.beltweigher.master.entity.MaterialName;
import com.hkts.beltweigher.master.mapper.MaterialNameMapper;
import com.hkts.beltweigher.master.service.IMaterialNameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.beltweigher.utils.CustomPage;
import com.hkts.beltweigher.utils.CustomPageUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hml
 * @since 2024-04-10
 */
@Service
@Transactional
public class MaterialNameServiceImpl extends ServiceImpl<MaterialNameMapper, MaterialName> implements IMaterialNameService {


    @Autowired
    private MaterialNameMapper materialNameMapper;

    @Override
    public IPage selectPage(Page<MaterialName> page, MaterialName materialName) {
        QueryWrapper<MaterialName> query = Wrappers.query();
        QueryWrapper<MaterialName> materialNameQueryWrapper = getEntityWrapper(query,materialName);
        System.out.println(page.getSize());
        return materialNameMapper.selectPage(page, materialNameQueryWrapper);
    }


    @Override
    public List<MaterialName> selectList(MaterialName materialName) {
        QueryWrapper<MaterialName> query = Wrappers.query();
        return materialNameMapper.selectList(query);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<MaterialName> getEntityWrapper(QueryWrapper<MaterialName> entityWrapper, MaterialName materialName) {
        //条件拼接
        if (StringUtils.isNotBlank(materialName.getName())) {
            entityWrapper.like(MaterialName.NAME, materialName.getName());
        }

        return entityWrapper;
    }


}
